Method and device for flexible buffering in networking system

ABSTRACT

A method and device for flexible, dynamic and optimal buffering in a networking system are provided. Sizes of incoming packets are recognized and the packets are buffered into buffers of appropriate sizes. Usage times of buffers are counted, and during an idle state of the networking system, buffer number and descriptor number are re-calculated based on usage times. Then, buffers and descriptors are re-allocated based on the re-calculated number. By re-allocation, buffer sets with higher usage times are allocated with more buffers, and vice versa, so memory waste is lowered and the overall performance of the networking system is improved.

BACKGROUND OF THE INVENTION

1. Field of Invention

The present invention relates to a method and device for flexiblebuffering in a networking system. More particularly, the presentinvention relates to a method and device for flexible buffering in anetworking system by dynamically and optimally reallocating buffer anddescriptor number.

2. Description of Related Art

The advent of networking systems has given rise to a number of devicesthat connect networking systems to packet-switched data network, such asthe Internet, LAN (local area network) or wireless network. Thesedevices typically include interfaces, for example a network interfacecard (interface unit), for the networking systems and the data networkfor buffering packets of data between the networking systems and thedata network. The buffer memory in these interfaces allows data receivedfrom the data network to be transmitted to the networking systems.

FIG. 1 shows a block diagram of a conventional networking system 100. Asshown in FIG. 1, the conventional networking system 100 at leastincludes a processor (for example, a central processing unit (CPU) or amicroprocessor) 101, a main memory 102 and an interface unit (forexample, a network interface card, NIC) 106. A descriptor group 103, adescriptor buffer group 104 and a socket buffer 105 are allocated in themain memory 102. The interface unit 106 at least includes a media accesscontrol (MAC) controller 107, which comprises an FIFO (first in firstout) buffer 108. The descriptor group 103, the descriptor buffer group104 and the socket buffer 105 are predetermined and allocated byoperation system (OS). In some cases, the descriptor buffer group isallocated from the socket buffer 105; in other words, the socket buffer105 includes the descriptor buffer group.

FIG. 2 shows the descriptor group 103 and the descriptor buffer group104. There are nine descriptors D 1, D 2 . . . and D 9 in the descriptorgroup 103. A descriptor is a data structure which records/points startaddress and size of the buffer in the descriptor buffer 104. Eachdescriptor is chained one next to another and the last one is chained tothe first one to form a “ring”. The descriptor buffer group 104 isdivided into nine descriptor buffers DB 1, DB 2 . . . and DB 9, all in1,024 bytes. One descriptor points to one descriptor buffer. Forexample, the descriptor D 1 points to the descriptor buffer DB 1, and soon.

Now please refer to FIG. 1 and FIG. 2 for an explanation of how theinterface unit 106 receives packet of data from a data network 109 andforwards the received packet to the main memory 102.

When the packet is input from the data network 109, it is put into theFIFO 108 of the MAC controller 107. Then, the MAC controller 107 fetchesone or more available descriptors D 1˜D 9 in the descriptor group 103,based on the size of the packet. If the packet is longer than the sizeof one buffer, then the packets are stored in two or more descriptorbuffers and the MAC controller 107 has to fetch two or more descriptors.The descriptor is not available if the descriptor buffer pointed by thedescriptor still stores the packet to be accessed by the processor 101and is not released yet. The MAC controller 107 moves the packet in theFIFO 108 to the descriptor buffer(s) pointed by the availabledescriptors. If the descriptor buffer is allocated from the socketbuffer, the processor 101 accesses the packet in the descriptor bufferand then releases the descriptor buffer and accordingly thecorresponding descriptor becomes available. If the descriptor buffer isnot allocated from the socket buffer, then the packet is moved againfrom the descriptor buffer into the socket buffer and the processor 101accesses the packet from the socket buffer.

Although it is easy for the conventional networking system to implementthe reception of packet from the data network 109, there are still somedisadvantages. First, the system lacks sensibility to packet size, whichleads to memory waste or redundant fetch of descriptors. When the sizeof the input packet is much smaller than the buffer size, only a fewportion of buffer is used and the remaining space is wasted. Forexample, if the input packet has a size of 24 bytes, then the remaining1000 (1024−24=1000) bytes of descriptor buffer are wasted because onlyone packet is allowed to be stored in one descriptor buffer at one time.On the other hand, if the input packet has a size larger than the sizeof the descriptor buffer, the MAC controller needs to fetch the nextdescriptor(s) and get more descriptor buffer(s) to store this longpacket. For example, if the long packet is of 2,500 bytes, then the MACcontroller needs to fetch three descriptors, for example D 2˜D 4, andget three descriptor buffers (DB 2˜DB 4) with a total of 3,072 bytes tostore this long packet. More descriptor fetch means more fetch cycles.Besides, if the descriptor buffer group 104 is not allocated from thesocket buffer 105, which is used by OS kernel, additional memory copy isrequired. Memory copy means packets in the descriptor buffer group 104are copied into the socket buffer 105. Memory copy increases burdens ofthe networking system.

Therefore, a new method and device for flexible buffering in networkingsystems is desired, which would make efficient use of the descriptorbuffer and prevent redundant descriptor fetch without increasing burdensof the networking system.

SUMMARY OF THE INVENTION

Accordingly, at least one objective of the present invention is toprovide a method and device for flexible buffering in a networkingsystem, which has enough sensibility to packet size.

Another objective of the present invention is to provide a method anddevice for flexible buffering in a networking system, capable ofallocating more buffers in a buffer set with more access/usage times andfewer buffers in a buffer set with fewer access/usage times, to enhanceoverall system performance.

According to one embodiment of the present invention, a method forflexible buffering in a networking system is provided. In the method,several buffer sets are allocated, while buffers in one buffer set havea different size from buffers in another buffer set. Upon receipt ofinput packets, packets are stored into buffers based on the packet size.Usage times of the buffer sets are counted, and then the buffer sets arere-allocated based on the usage times.

In another embodiment of the present invention, a networking system withflexible buffering is provided. In the system, a main memory isallocated with several buffer sets having buffers of different sizes,and a networking controller receives and buffers input packets intobuffers based on the packet size. When the networking system is idling,buffer number in the buffer sets are recalculated based on the usagetimes of the buffer sets, and the buffer sets are redefined based on therecalculated buffer number.

In still another embodiment of the present invention, a networkinginterface in a networking system with a main memory is provided. Theinterface receives and moves packets to the main memory which isallocated with several buffer sets having buffers of different sizes.The main memory further allocates several descriptor sets pointing tobuffer sets. In the networking interface, a networking controllerreceives and buffers input packets into the buffers based on the packetsize. The networking controller includes a status register, indicatingwhether packets are stored in the buffers, and a counter, counting usagetimes of the buffer sets. The networking controller re-calculates thedescriptor number in the descriptor sets and buffer number in the buffersets based on values of the counter when the networking system isidling, and the descriptor sets and the buffer sets are re-allocatedbased on the re-calculated number.

With the present method and device for flexible, dynamic and optimalbuffering in a networking system, buffer sets with higher usage timesare allocated with more buffers, and buffer sets with lower usage timesare allocated with fewer buffers. According to the invention, memorywaste and redundant descriptor fetch are lowered, so the overallperformance of the networking system is improved.

It is to be understood that both the foregoing general description andthe following detailed description are exemplary, and are intended toprovide further explanation of the invention as claimed.

BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings are included to provide a furtherunderstanding of the invention, and are incorporated in and constitute apart of this specification. The drawings illustrate embodiments of theinvention and, together with the description, serve to explain theprinciples of the invention.

FIG. 1 is a block diagram of a conventional networking system.

FIG. 2 shows the descriptor group and the descriptor buffer group usedin FIG. 1.

FIG. 3 shows a flow chart for flexible buffering according to anembodiment of the present invention.

FIG. 4 shows initial states of a descriptor group and a descriptorbuffer group according to an embodiment of the present invention.

FIG. 5 shows reallocated states of the descriptor group and thedescriptor buffer group according to an embodiment of the presentinvention.

FIG. 6 shows a block diagram of a networking system for flexiblebuffering according to an embodiment of the present invention.

DESCRIPTION OF THE EMBODIMENTS

Reference will now be made in detail to the present embodiments of theinvention, examples of which are illustrated in the accompanyingdrawings. Wherever possible, the same reference numbers are used in thedrawings and the description to refer to the same or like parts.

Please refer to FIGS. 3˜5 for detailed description of the embodiments ofthe present invention. FIG. 3 shows a flow chart of flexible bufferingaccording to an embodiment of the present invention. FIG. 4 showsinitial states of a descriptor group and a descriptor buffer group. FIG.5 shows reallocated states of the descriptor group and the descriptorbuffer group.

As shown in FIG. 3, in step S31, M (wherein M is a natural number equalto or smaller than 6, for example, M=4) sets of descriptor buffers(hereinafter, “buffers”) are allocated. It is preferred that the buffersare allocated from a socket buffer for preventing additional memory copyand increasing system performance.

In step S32, M descriptor sets are mapped to the M buffer sets. Oneexample of initial states of the allocation and mapping of thedescriptors and the buffers is shown in FIG. 4. As shown in FIG. 4, eachdescriptor set includes N (wherein N is a natural number, for example,N=9) chained descriptors, wherein the last one is chained to the firstone to form a “ring”. The first descriptor set includes 9 chaineddescriptors, D 1,1, D 1,2, D 1,3, D 1,4, D 1,5, D 1,6, D 1,7, D 1,8 andD 1,9. The second descriptor set includes 9 chained descriptors, D 2,1˜D2,9. The third descriptor set includes 9 chained descriptors, D 3,1˜D3,9. The fourth descriptor set includes 9 chained descriptors, D 4,1˜D4,9. Each buffer set is provided with N buffers of identical size, butbuffers in different buffer set are of different sizes. For example, 1stbuffer set is divided into 9 buffers of 64 bytes, DB 1,1, DB 1,2, DB1,3, DB 1,4, D 1,5, DB 1,6, D 1,7, DB 1,8 and DB 1,9. The second bufferset is divided into 9 buffers of 256 bytes, DB 2,1˜DB 2,9. The thirdbuffer set is divided into 9 buffers of 512 bytes, DB 3,1˜DB 3,9. Thefourth buffer set is divided into 9 buffers of 1024 bytes, DB 4,1˜DB4,9. One descriptor points to one buffer. For example, the descriptor D1,1 points to the buffer DB 1,1; the descriptor D 1,2 points to thebuffer DB 1,2; . . . and the descriptor D 4,9 points to the buffer DB4,9. Of course, initial states of the descriptors and buffers are notlimited to 4 sets and 9 descriptors/buffers.

In step S33, the MAC controller is set and initialized. The setting ofthe MAC controller at least includes setting descriptor interrupt statusregisters (DISR) and buffer statistics usage counters (BSUC). One DISRis related to one descriptor set. DISR indicates whether a bufferpointed by the corresponding descriptor keeps the packets to beaccessed. If there are four descriptor sets at the beginning, then fourDISRs in the MAC controller are set and in a one-on-one relation to thefour descriptor sets. The BSUCs count the usage times of each of thebuffer sets; in other words, if a packet is buffered in DB 1,1 of thefirst buffer set, then a first BSUC counts one, or the count value ofthe first BSUC is updated/increased by 1. As shown in FIG. 4, if thereare four buffer sets at the beginning, then four BSUCs in the MACcontroller are set in one-on-one relation to the four buffer sets. Ininitialization, values of the BSUCs are set to zero.

In step S34, set and initialized, the MAC controller is ready to receiveincoming packets. After packets are received and stored in the FIFOinside the MAC controller, the MAC controller classifies and buffers theincoming packets in the descriptor buffer group in the main memory basedon the packet size. The MAC controller recognizes the packet size fromthe header of the incoming packets. The classifying and bufferingcriteria are as follows. If the packet size≦64 bytes, the packet isbuffered in the first buffer set in which each buffer is 64 bytes. If 64bytes<packet size≦256 bytes, the packet is buffered in the second bufferset in which each buffer is 256 bytes. If 256 bytes≦packet size≦512bytes, the packet is buffered in the third buffer set in which eachbuffer is 512 bytes. If the packet size>512 bytes, the packet isbuffered in the fourth buffer set in which each buffer is 1,024 bytes.After the incoming packets are buffered in appropriate buffers, thecorresponding BSUC is updated.

For example, after the MAC controller is set up and initialized, if apacket of 200 bytes is input, the MAC controller buffers the inputpacket in DB 2, 1 of the second buffer set and value of the second BSUCis updated from zero to 1. Then, if a packet of 50 bytes is input, theMAC controller buffers the input packet in DB 1, 1 of the first bufferset and value of the first BSUC is updated from zero to 1.

When the packets are moved to the buffer by the MAC controller, theprocessor receives an interrupt command and jumps to an ISR (interruptservice routine), as shown in step S35.

In step S36, ISR checks whether the DISR is set. If a DISR is set, whichmeans there are remaining packets buffered in buffers pointed by thedescriptor corresponding to the set DISR, then the processor accessesthe remaining packets in the buffers and clears an Own Bit in thecorresponding descriptor. The Own Bit indicates whether the bufferpointed by the descriptor is empty. If the Own Bit is cleared (forexample, “0”), the buffer is empty and the descriptor is available. Ifthe Own Bit is set (for example, “1”), the buffer is buffered by theincoming packets.

After receiving multiple packets, the MAC controller may be in an idlestate, which means there are no incoming packets for a while. Beforeentering into an idle state, it is checked whether any packets remain inevery buffer. If there is no remaining packet, the MAC controller entersinto an idle state. If some packets remain in the buffers, the processorkeeps on accessing those remaining packets. In an idle state, the MACcontroller calculates usage times/rates of each buffer set based onBSUC, as shown in step S37, and then recalculates each descriptor amountof each descriptor set (or each buffer amount of each buffer set) basedon the usage times/rates, as shown in step S38.

The MAC controller calculates the descriptor amounts in descriptor sets(or buffer amounts in buffer sets) by the following equation:Nk _(—) r=(N _(—) p+N2_(—) p+N3_(—) p+N4_(—) p+ . . . NM _(—) p)*Uk  (1)

wherein k=1˜M; Nk_r refers to updated descriptor amounts of k-thdescriptor sets or updated buffer amounts in k-th buffer sets; Nk_prefers to the original descriptor amounts of k-th descriptor sets ororiginal buffer amounts in k-th buffer sets; and Uk refers to the usagerates of k-th buffer sets.

Taking FIG. 4 for an example, four buffer sets, each of which has ninebuffers, is shown; that is, k=4 and N1_p=N2_p=N3_p=N4_p=9. Assuming inan idle state, the values of four BSUCs are 100, 150, 150 and 50,respectively. The usage rates of four buffer sets are respectivelyU1=22% (or 2/9), U2=33% (or ⅓), U3=33% (or ⅓) and U4=11% (or 1/9). Byequation (1),N1_(—) r=(9+9+9+9)*22%=8  (2)N2_(—) r=(9+9+9+9)*33%=12  (3)N3_(—) r=(9+9+9+9)*33%=12  (4)N4_(—) r=(9+9+9+9)*11%=4  (5)

Then, it is confirmed again that there are no packets remaining in everybuffer, as shown in step S39. If some packets still remain in thebuffers, the processor keeps on accessing packets, as shown in step S40.If no packets remain, the MAC controller is disabled for a while. Whenthe MAC controller is disabled, incoming packets are blocked, if any, asshown in step S41.

The MAC controller re-allocates or releases descriptor and buffers basedon the updated descriptor amounts and buffer amounts, as shown in stepS42. By above equations (2)˜(5), after being re-allocated or released,eight descriptors D 1,1˜D 1,8 are contained in the first descriptor set;twelve descriptors D 2,1˜D 2,12 are contained in the second descriptorset; twelve descriptors D 3,1˜D 3,12 are contained in the thirddescriptor set; and four descriptors D 4,1˜D 4,4 are contained in thefourth descriptor set. Similarly, after the rearrangement, eight buffersDB 1,1˜DB 1,8 are contained in the first buffer set; twelve buffers DB2,1˜DB 2,12 are contained in the second buffer set; twelve buffers DB3,1˜DB 3,12 are contained in the third buffer set; and four buffers DB4,1˜DB 4,4 are contained in the fourth buffer set. FIG. 5 showsre-allocated states of the descriptor group and the descriptor buffergroup as discussed above.

It is noted that, after calculation by equation (1), if the updateddescriptor (or buffer) amount is 0, it is recommended the updateddescriptor (or buffer) amount be set as 1, instead of 0.

After the rearrangement of descriptors and buffers, the four BSUCs areall cleared, or values of four BSUCs are reset as 0, and the MACcontroller are reset, as shown in step S43. Then, it is checked whetherthe networking system is still at work, as shown in step S44. If yes,the process returns to step S34 as shown in step S45. If not, theprocess ends.

For better performance, it is preferred that the descriptor buffer groupis allocated from socket buffers.

FIG. 6 shows a block diagram of the networking system for flexiblebuffering according to an embodiment of the present invention. As shownin FIG. 6, the networking system 200 includes a processor 210, a mainmemory 220 allocated with the descriptor group 221 and the descriptorbuffer group 222, and a MAC controller 235 with a DISR 236, a BSUC 237and an FIFO buffer 238.

As discussed above, in the present invention, amounts of descriptors andbuffers are flexibly updated based on the previous usage times/rates ofbuffers, to increase system performance. After update, buffer set withmore access/usage times/rates contains more buffers, and vice versa.Besides, by allocating several buffer sets with buffers of differentbytes, the memory waste of buffer is reduced and the descriptor fetchcycles may be lowered because incoming packets are buffered into bufferswith appropriate size.

The networking system includes, for example but not limited to, acomputer system with a network interface card (NIC), an embedded systemwith networking access, a router, a switch, a home appliance withnetworking access, a wireless PDA (personal digital assistant), acellular phone with networking access, a firewall device, a gateway andother similar devices with networking access.

It will be apparent to those skilled in the art that variousmodifications and variations can be made to the structure of the presentinvention without departing from the scope or spirit of the invention.In view of the foregoing descriptions, it is intended that the presentinvention covers modifications and variations of this invention if theyfall within the scope of the following claims and their equivalents.

1. A method for flexible buffering in a networking system, comprising:allocating first and second buffer sets, buffers in the first buffersets having a different size from buffers in the second buffer set;receiving input packets; buffering input packets into the buffer in oneof the first and second buffer sets based on a packet size; countingusage times of the first and second buffer sets; and reallocating thefirst and second buffer sets based on the usage times.
 2. The method ofclaim 1, further comprising a step of allocating the first and seconddescriptor sets with first and second descriptors pointing to thebuffers in the first and second buffer sets.
 3. The method of claim 1,wherein the first and second buffer sets are allocated from a socketbuffer in a main memory of the networking system.
 4. The method of claim1, wherein the step of counting usage times comprises: updating a firstcount value when the input packet is buffered in the buffers of thefirst buffer set; and updating a second count value when the inputpacket is buffered in the buffers of the second buffer set.
 5. Themethod of claim 2, further comprising: accessing packets from thebuffer; and clearing an own bit in the descriptor pointing to thebuffers.
 6. The method of claim 2, further comprising a step ofre-calculating descriptor amounts in the first and second descriptorsets and buffer amounts in the first and second buffer sets based on thecounted usage times.
 7. The method of claim 6, further comprising a stepof re-allocating or releasing the descriptors in the first and seconddescriptor sets and the buffers in the first and second buffer setsbased on the re-calculated descriptor amounts and buffer amounts.
 8. Themethod of claim 1, wherein the networking system is selected from agroup comprising a computer system with a network interface card (NIC),an embedded system with networking, a router, a switch, a home appliancewith networking, a wireless PDA (personal digital assistant), a cellularphone with networking, and a firewall device and a gateway.
 9. Anetworking system for receiving packets, comprising: a main memory,allocated with first and second buffer sets having buffers of differentsizes; and a networking controller, receiving and buffering inputpackets into the buffer in one of the first and second buffer sets basedon a packet size; wherein when the networking system is idling, buffernumbers in the first and second buffer sets are recalculated based onthe usage times of the first and second buffer sets, and the first andsecond buffer sets are redefined based on the recalculated buffernumbers.
 10. The networking system of claim 9, wherein the main memoryfurther allocates first and second descriptor sets with first and seconddescriptors pointing to the buffers in the first and second buffer sets.11. The networking system of claim 9, wherein the first and secondbuffer sets are allocated from a socket buffer in the main memory. 12.The networking system of claim 9, wherein the networking controllercomprises first and second counters for updating the usage times whenthe input packet is buffered in the buffers of one of the first andsecond buffer sets.
 13. The networking system of claim 10, furthercomprising a processor for accessing packets from the buffer andclearing an own bit in the descriptor pointing to the buffer.
 14. Thenetworking system of claim 10, wherein descriptor amounts in the firstand second descriptor sets and buffer amounts in the first and secondbuffer sets are recalculated based on the usage times.
 15. Thenetworking system of claim 14, wherein the descriptors in the first andsecond descriptor sets and the buffers in the first and second buffersets are re-allocated or released based on the recalculated descriptorand buffer amounts.
 16. The networking system of claim 9, wherein thenetworking system is selected from a group comprising a computer systemwith a network interface card (NIC), an embedded system with networkingaccess, a router, a switch, a home appliance with networking access, awireless PDA (personal digital assistant), a cellular phone withnetworking access, and a firewall device and a gateway.
 17. A networkinginterface in a networking system with a main memory, receiving andmoving packets to the main memory, the main memory allocated with firstand second buffer sets having buffers of different sizes and first andsecond descriptor sets pointing to first and second buffer sets, thenetworking interface comprising: a networking controller, receiving andbuffering input packets into the buffer in one of the first and secondbuffer sets based on a packet size, the networking controllingcomprising: a status register, indicating whether packets are stored inthe buffers; and a counter, counting the usage times of buffers in thefirst and second buffer sets; wherein the networking controllerre-calculates descriptor numbers in the first and second descriptor setsand buffer numbers in the first and second buffer sets based on valuesof the counter, and the first and second descriptor sets and the firstand second buffer sets are re-allocated based on the re-calculatednumber.
 18. The networking interface of claim 17, wherein the networkingsystem further comprises a processor for accessing packets from thebuffer and clearing an own bit in the descriptor pointing to the buffer.19. The networking interface of claim 17, wherein the networking systemis selected from a group comprising a computer system with a networkinterface card (NIC), an embedded system with networking access, arouter, a switch, a home appliance with networking access, a wirelessPDA (personal digital assistant), a cellular phone with networkingaccess, a firewall device and a gateway.